package springstudy.condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * 系统属性条件判断
 * @Author acy
 * @Date 2019/04/24
 */
public class OnSystemPropertyCondition implements Condition {
	@Override
	public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
		Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnSystemProperty.class.getName());
		String propertyName = String.valueOf(attributes.get("name"));
		String propertyValue = String.valueOf(attributes.get("value"));
		String javaProperty = System.getProperty(propertyName);
		return propertyValue.equals(javaProperty);
	}
}
